//
//  YQPPThirdViewController.m
//  项目基础框架
//
//  Created by NetEase on 16/3/10.
//  Copyright © 2016年 NetEase-yangqian. All rights reserved.
//

#import "YQPPThirdViewController.h"
#import "YQPPTransformButton.h"

@interface YQPPThirdViewController ()<UITableViewDataSource,YQPPTransformButtonEndDragDelegate>

@property (strong, nonatomic) YQPPTransformButton *transformBtn;
@property (strong, nonatomic) UITableView *tableView;
@end

@implementation YQPPThirdViewController
{
@private
    UIImageView *_bgImage;//头部的背景图片
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor blueColor];
    self.navigationItem.title = @"我的圈";
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style: UITableViewStylePlain];
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
    [self.view addSubview:_tableView];
    
    UIView *headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 300)];
    self.tableView.tableHeaderView = headView;
    
    // 放置按钮的自定义视图
    _bgImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, -100, self.view.frame.size.width, 400)];
    [_bgImage setImage:[UIImage imageNamed:@"bg_image"]];
    [headView addSubview:_bgImage];
    _transformBtn = [YQPPTransformButton transformButtonWithFrame:CGRectMake(20, -30, 25, 25)
                                                        imageName:@"wechat_moment"
                                                   transformImage:@"wechat_moment"];
    _transformBtn.deleagte = self;
    UIButton *rightButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
    [rightButton setImage:[UIImage imageNamed:@"publish_commnet"] forState:UIControlStateNormal];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];
    
    // 放到自定义view上
    [headView addSubview:_transformBtn];
    self.tableView.delegate = _transformBtn;
    self.tableView.dataSource = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - tableview datasouce
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    return cell;
}

- (void)endDrag {
    // 模拟网络加载延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [_transformBtn endTransform];
    });
    
}

@end
